package main

import (
	"fmt"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
)

func main() {
	router := httprouter.New()
	router.GET("/", Index)
	// 捕获异常
	router.PanicHandler = func(writer http.ResponseWriter, request *http.Request, v interface{}) {
		writer.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintf(writer, "error:%s", v)
	}

	log.Fatal(http.ListenAndServe(":80", router))
}

func Index(w http.ResponseWriter, req *http.Request, _ httprouter.Params)  {
	panic("thi is as error")
}

